package com.fairytask.utils
{
	import flash.geom.Point;

	public class Vec2D
	{
		public var x:Number=0;
		public var y:Number=0;
		
		public function Vec2D(arg1:Number=0, arg2:Number=0)
		{
			super();
			this.x = arg1;
			this.y = arg2;
			return;
		}
		
		public function cross(arg1:Vec2D):Number
		{
			return this.x * arg1.y - this.y * arg1.x;
		}
		
		public function divVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(this.x / arg1.x, this.y / arg1.y);
		}
		
		public function toString():String
		{
			return this.x.toString() + " " + this.y.toString();
		}
		
		public function dot(arg1:Vec2D):Number
		{
			var loc1:*=this.x * arg1.x + this.y * arg1.y;
			return loc1;
		}
		
		public function mulN(arg1:Number):void
		{
			this.x = this.x * arg1;
			this.y = this.y * arg1;
			return;
		}
		
		public function addN(arg1:Number):void
		{
			this.x = this.x + arg1;
			this.y = this.y + arg1;
			return;
		}
		
		public function subN(arg1:Number):void
		{
			this.x = this.x - arg1;
			this.y = this.y - arg1;
			return;
		}
		
		public function get point():Point
		{
			return new Point(this.x, this.y);
		}
		
		public function isLeft(arg1:Vec2D):Boolean
		{
			return this.cross(arg1) >= 0 ? true : false;
		}
		
		public function mulV(arg1:Vec2D):void
		{
			this.x = this.x * arg1.x;
			this.y = this.y * arg1.y;
			return;
		}
		
		public function get angle():Number
		{
			var loc1:*=Math.atan2(this.y, this.x) * 180 / Math.PI;
			if (loc1 < 0) 
			{
				loc1 = loc1 + 360;
			}
			return loc1;
		}
		
		public function get vec():Vec2D
		{
			return new Vec2D(this.x, this.y);
		}
		
		public function addV(arg1:Vec2D):void
		{
			this.x = this.x + arg1.x;
			this.y = this.y + arg1.y;
			return;
		}
		
		public function subV(arg1:Vec2D):void
		{
			this.x = this.x - arg1.x;
			this.y = this.y - arg1.y;
			return;
		}
		
		public function project(arg1:Vec2D):Vec2D
		{
			var loc1:Number=this.dot(arg1);
			var loc2:Number=arg1.dot(arg1);
			var loc3:Number=loc1 / loc2;
			return arg1.mulNum(loc3);
		}
		
		public function get len():Number
		{
			return Math.sqrt(this.x * this.x + this.y * this.y);
		}
		
		public function divN(arg1:Number):void
		{
			this.x = this.x / arg1;
			this.y = this.y / arg1;
			return;
		}
		
		public function set point(arg1:Point):void
		{
			this.x = arg1.x;
			this.y = arg1.y;
			return;
		}
		
		public function mulNum(arg1:Number):Vec2D
		{
			return new Vec2D(this.x * arg1, this.y * arg1);
		}
		
		public function getAngle(arg1:Vec2D):Number
		{
			var loc1:Number=this.nDot(arg1);
			return Math.acos(loc1) * 180 / Math.PI;
		}
		
		public function divV(arg1:Vec2D):void
		{
			this.x = this.x / arg1.x;
			this.y = this.y / arg1.y;
			return;
		}
		
		public function subNum(arg1:Number):Vec2D
		{
			return new Vec2D(this.x - arg1, this.y - arg1);
		}
		
		public function get normal():Vec2D
		{
			return new Vec2D(-this.y, this.x);
		}
		
		public function set vec(arg1:Vec2D):void
		{
			this.x = arg1.x;
			this.y = arg1.y;
			return;
		}
		
		public function get reverse():Vec2D
		{
			return new Vec2D(-this.x, -this.y);
		}
		
		public function addNum(arg1:Number):Vec2D
		{
			return new Vec2D(this.x + arg1, this.y + arg1);
		}
		
		public function set angle(arg1:Number):void
		{
			var loc1:*=arg1 * Math.PI / 180;
			this.x = Math.cos(loc1);
			this.y = Math.sin(loc1);
			return;
		}
		
		public function normalize():void
		{
			var loc1:*=this.len;
			var loc2:*=new Vec2D(0, 0);
			loc2.x = this.x / loc1;
			loc2.y = this.y / loc1;
			this.vec = loc2;
			return;
		}
		
		public function subVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(this.x - arg1.x, this.y - arg1.y);
		}
		
		public function divNum(arg1:Number):Vec2D
		{
			return new Vec2D(this.x / arg1, this.y / arg1);
		}
		
		public function mulVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(this.x * arg1.x, this.y * arg1.y);
		}
		
		public function addVec(arg1:Vec2D):Vec2D
		{
			return new Vec2D(this.x + arg1.x, this.y + arg1.y);
		}
		
		public function nDot(arg1:Vec2D):Number
		{
			var loc1:*=this.normalized;
			var loc2:*=arg1.normalized;
			var loc3:*;
			return loc3 = loc1.x * loc2.x + loc1.y * loc2.y;
		}
		
		public function get len2():Number
		{
			return this.x * this.x + this.y * this.y;
		}
		
		public function get normalized():Vec2D
		{
			var loc1:Number=this.len;
			var loc2:Vec2D=new Vec2D(0, 0);
			loc2.x = this.x / loc1;
			loc2.y = this.y / loc1;
			return loc2;
		}
		
	}
}